package com.oocl.Homework3;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class ReadFile
{
	public TreeSet<Customer> set1 = new TreeSet<Customer>(); 
	TreeSet<Customer> set2;
	public boolean processLine(String line)
	{
		String[] strs=line.split(" ");
		RegexExpression rx=new RegexExpression();
		if(!rx.RegexFilter(strs[0], strs[1], strs[4], strs[2]))
			return false;
		else
		{
			Customer customer=new Customer(strs[0],strs[1],strs[2],strs[3],strs[4]);
			set1.add(customer);
			return true;
		}
	}
	public void read()
	{
		Scanner scanner = null;
		try {
			scanner = new Scanner(new FileInputStream("customer"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		String line = null;
		while(scanner.hasNext())
		{
			line=scanner.nextLine();
			processLine(line);
		}
	}
	
	public void SortByDate()
	{
		DateComparator comparator = new DateComparator(); 
		set2 = new TreeSet<Customer>(comparator); 
		
		for(Customer customer : set1)
			set2.add(customer);
	}
}

